<?php
/**
 * Created by PhpStorm.
 * User: Yui
 * Date: 2017/5/9 0009
 * Time: 11:06
 */

namespace common\services;
use common\models\PersonnelClass;


class PersonnelClassSve extends BaseSve
{
    public function getList($where = [], string $orderBy = '', bool $isPaging = false):array
    {
        $PersonnelClass = PersonnelClass::find()->where($where)->orderBy($orderBy)->asArray()->all();
        return $PersonnelClass;
    }


    //获取层级关系
    public function getRole($role)
    {
        $data['parent_role']=0;
        $data['ancestors_role']=0;
        //获取父级id
        $parentInfo = PersonnelClass::find()->where(['personnel_class_id'=>$role])->one();

        if($parentInfo && $parentInfo['parent_id']){
            $data['parent_role']=$parentInfo['parent_id'];
            //获取祖级id
            $ancestorsInfo = PersonnelClass::find()->where(['personnel_class_id'=>$parentInfo['parent_id']])->one();
            if ($ancestorsInfo && $ancestorsInfo['parent_id']){
                $data['ancestors_role']=$ancestorsInfo['parent_id'];
            }
        }
        return $data;
    }

}